import React from 'react';
import CommentList from './CommentList';
import CommentForm from './CommentForm';
import moment from 'moment';

export default class Comment extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            conmmentList: [
                {
                    id: "5433d5e4e737cbe96dcef312",
                    name: '张三',
                    content: '第一条评论',
                    date: moment().format('YYYY-MM-DD HH:mm:ss')
                },{
                    id: "5433d5e4e737cbe96dcef212",
                    name: '李四',
                    content: '第二条评论',
                    date: moment().format('YYYY-MM-DD HH:mm:ss')
                }
            ]
        }
        this.addComment = this.addComment.bind(this);
    }

    addComment(item) {
        const { conmmentList } = this.state;
        conmmentList.push(item);
        this.setState({
            conmmentList
        });
    }

    render() {
        return (
            <React.Fragment>
                <CommentForm addComment={this.addComment}/>
                    <div className="line"></div>
                <CommentList commentList={this.state.conmmentList} />
            </React.Fragment>
        );
    }
}


